using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using HappyFrogXna.ScreenSystem;
using FarseerPhysics.Factories;
using HappyFrogXna.Miscellaneous;
using FarseerPhysics.Collision.Shapes;

namespace HappyFrogXna.Roles
{
    class CircleEntity : Entity
    {
        public CircleEntity(World w, Vector2 pos)
            : base(w, pos)
        { }

        public override Entity Clone()
        {
            Entity entity = EntityCreator.CreateEntity(this.UserDate.Name, _world);//new Entity(world, Position);

            float radius = ConvertUnits.ToSimUnits(EntitySprite.Height / 2);
            float density = EntityBody.FixtureList[0].Shape.Density;
            entity.EntityBody = BodyFactory.CreateEllipse(_world, radius, radius, 8, density, Position);
            entity.EntityBody.BodyType = this.EntityBody.BodyType;
            entity.EntityBody.Rotation = this.EntityBody.Rotation;
            entity.EntityBody.Mass = this.EntityBody.Mass;
            entity.EntityBody.Restitution = this.EntityBody.Restitution;
            entity.EntityBody.Friction = this.EntityBody.Friction;

            entity.EntitySprite = this.EntitySprite;
            entity.Rotation = this.Rotation;
            entity.IsActive = this.IsActive;
            entity.IsVisible = this.IsVisible;

            entity.UserDate = this.UserDate.Clone();

            return entity;
        }

        public override bool IsTouched(Vector2 pos, float extend)
        {
            float radius = ConvertUnits.ToSimUnits((this.Texture.Height + extend) * _scaleRadio / 2);
            return GameMathHelper.DistanceOfPos(pos, this.Position) < radius;
        }
    }
}
